package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import java.util.Locale;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ColumnNameTypeListContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.DataSourceNameContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ExpressionContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SourceAliasContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.DataSourceBodyContext;

/**
 * DataSource Body 语法遍历
 * @author zwd
 *
 */
public class DatasourceBodyVisitor extends AbsCQLParserBaseVisitor<DataSourceBodyContext>{

	private DataSourceBodyContext context = null;
	
	public DatasourceBodyVisitor() {
		context = new DataSourceBodyContext();
	}
	
	@Override
	protected DataSourceBodyContext defaultResult() {
		return context;
	}
	
	@Override
	public DataSourceBodyContext visitDataSourceName(@NotNull DataSourceNameContext ctx) {
		context.setDataSourceName(ctx.getText().toLowerCase(Locale.US));
        return context;
	}
	
	@Override
	public DataSourceBodyContext visitSourceAlias(@NotNull SourceAliasContext ctx) {
		SourceAliasVisitor visitor = new SourceAliasVisitor();
        context.setAlia(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public DataSourceBodyContext visitColumnNameTypeList(@NotNull ColumnNameTypeListContext ctx) {
		ColumnNameTypeListVisitor visitor = new ColumnNameTypeListVisitor();
        context.setSchemaColumns(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public DataSourceBodyContext visitExpression(ExpressionContext ctx) {
		ExpressionVisitor visitor = new ExpressionVisitor();
        context.getQueryarguments().add(visitor.visit(ctx));
        return context;
	}

}
